const DB = require('../tools/mysql')

module.exports = async ctx => {

  const { id, type } = ctx.request.body

  let table = ''
  switch (type) {
    case '0':
      table = 'village_registry'
      break
    case '1':
      table = 'home_registy'
      break
    case '2':
      table = 'three_implementation'
    case '3':
      table = 'issue_list'
      break
    default:
      table = 'village_registry'
  }

  const [{ files }] = await DB(table).select('files').where('id', id)

  const filelist = files.split(','),
    data = []
  for (var i = 0; i < filelist.length; i++) {
    const [file] = await DB('files').where('id', filelist[i])
    data.push(file)
  }

  ctx.body = { code: 1, msg: '查询成功', data }

}